package com.tencent.welink.api.msg;

import com.alibaba.fastjson.JSONObject;
import com.tencent.welink.api.base.WelinkOpenApi;
import com.tencent.welink.config.BussinessConfig;
import com.tencent.welink.util.CrontabUtil;
import com.tencent.welink.api.OpenApiTokenChange;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Map;

/**
 * Created by junchihe on 2020/6/4.
 * desc:发送消息到设备
 * 描述：用于发送自定义数据格式的消息，通过微瓴透传给智能设备，并在设备中进行协议解析
 */
public class ToDeviceMsgSend extends WelinkOpenApi {
    private static final Logger log = LogManager.getLogger(ToDeviceMsgSend.class);
    public ToDeviceMsgSend() {
        super("/common/msg/send",true);
    }
    @Override
    public void displayResult(String result) {

    }

    public static void main(String[] args) {
        new BussinessConfig();
        CrontabUtil.addTaskInRate(new OpenApiTokenChange(), BussinessConfig.loginDurationMinutes,true);
        ToDeviceMsgSend toDeviceMsgSend =   new ToDeviceMsgSend();
        Map<String,Object> map = toDeviceMsgSend.getExtendsPara();

        /**
         * 字段名称	字段类型	是否必须	字段描述
         * token	String	是	鉴权参数：登录获取的动态密钥
         * iotim_ticket	String	是	鉴权参数：登录获取的物联票据
         * wId	String	是	设备的唯一标识
         * datapoint	Long	是	在微瓴物联平台申请的功能 ID
         * cmd	String	是	给设备发送消息的内容，需 UrlEncode
         */
        map.put("datapoint",10000084);
        map.put("din","300000000000070688");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("cmd","ClosePushStream");

        map.put("cmd", jsonObject.toJSONString());
            // map.put("page",1);
        toDeviceMsgSend.DoHttp();
        CrontabUtil.shutdown();

    }
}
